package com.zhengke.service.xwgl;

import java.io.IOException;
import java.util.List;

import com.zhengke.common.util.LoadProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.object.AjaxDone;
import com.zhengke.common.object.Result;
import com.zhengke.dao.XWGLDao;
import com.zhengke.pojo.JournalismPhone;

@Service
public class XWGLServiceImpl implements XWGLService {

	@Autowired
	private XWGLDao dao;
	
	@Override
	public Result queryXW(int pageNum,int size) {
		/**
		 * 	开启分页
		 */
		PageHelper.startPage(pageNum,size,true);
		List<JournalismPhone> list= dao.queryXW();
		//读取config.properties查找访问路径的ip+端口
		String fileServerUrl = null;
		try {
			fileServerUrl = LoadProperties.findValue("FILE_SERVER_URL");
		} catch (IOException e) {
			e.printStackTrace();
		}

		for (JournalismPhone journalismPhone : list){
			String titleImg = fileServerUrl+journalismPhone.getTitleImg();
			journalismPhone.setTitleImg(titleImg);
		}
		PageInfo<JournalismPhone> pageInfo = new PageInfo<JournalismPhone>(list);
		Result rs = new Result();
		rs.setCode("0");
		rs.setCount(pageInfo.getTotal());
        rs.setData(list);	
		return rs;
	}

	@Override
	public int addxw(JournalismPhone jp) {
		return dao.addxw(jp);
	}

	@Override
	public AjaxDone delxw(String id) {
		int num = dao.delxw(id);
		if(num>0) {
			return new AjaxDone("200","删除成功");
		}
		return new AjaxDone("300","系统繁忙请稍后再试！");
	}

	@Override
	public int updxw(JournalismPhone jp) {
		int num = dao.updxw(jp);

		return num;
	}

}
